﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        NetManager.AddEventListener(NetManager.NetEvent.ConnectSucc,OnConnectSucc);
        NetManager.AddEventListener(NetManager.NetEvent.ConnectFail,OnConnectFail);
        NetManager.AddEventListener(NetManager.NetEvent.Close,OnConnectClose);
        NetManager.AddMsgListener("MsgMove",OnMsgMove);
    }

    private void Update()
    {
        NetManager.Update();
    }

    public void OnConnectClick()
    {
        NetManager.Connect("127.0.0.1",8888);
    }

    public void OnCloseClick()
    {
        NetManager.Close();
    }
    public void OnMoveClick()
    {
        MsgMove msg = new MsgMove();
        msg.x = 120;
        msg.y = 123;
        msg.z = -6;
        NetManager.Send(msg);
    }
    private void OnConnectSucc(string err)
    {
        Debug.Log("OnConnectSucc");
    }
    
    private void OnConnectFail(string err)
    {
        Debug.Log("OnConnectFail");
    }
    private void OnConnectClose(string err)
    {
        Debug.Log("OnConnectClose");
    }

    public void OnMsgMove(MsgBase msgBase)
    {
        MsgMove msg = (MsgMove)msgBase;
        Debug.Log("OnMsgMove msg.x="+msg.x);
        Debug.Log("OnMsgMove msg.y="+msg.y);
        Debug.Log("OnMsgMove msg.z="+msg.z);
    }
    
}
